import Vue from 'vue';
import store from '../../index'
async function initCurrentUser(jsonObj){
    if(Vue.prototype.isIphone && jsonObj){
        jsonObj = JSON.parse(jsonObj);
    }
    if(jsonObj.constructor && Object.keys(jsonObj).length > 0){
        // $('html,body,#app').css({'background-color':'transparent!important'});
        let obj = jsonObj;
        let user={
            chatAccount: obj && obj.chatAccount ? obj.chatAccount : '',
            configLoginPwd: obj.configLoginPwd || false,
            configPayPwd: obj.configPayPwd || false,
            configUserPortrait: obj.configUserPortrait || false,
            gender: 0,
            openId: null,
            phone: obj.phone || "",
            photoUrl: obj.photoUrl || "",
            thirdId: null,
            userId: obj.userId,
            userName: obj.userName,
        }
        Vue.prototype.userId = obj.userId;
        await store.dispatch('updateCurrentUser',user)
    }
}
export default {
    hkhwUserInfo(state,locationObj){
        window.initCurrentUser = initCurrentUser;
        let locationSearch = Vue.prototype.locationSearch(window.location.search);
        if( locationSearch && (locationSearch.ttn == 5 || locationSearch.isHKHW == true || locationSearch.isHKHW == 'true') ){
            let userInfo = '';
            // window.refreshAppraiseTime = this.refreshAppraiseTime;
            if(Vue.prototype.isAndroid && window.htmlInteracAndroid){
                userInfo = window.htmlInteracAndroid.h5needLoginfo();
                userInfo = JSON.parse(userInfo);
            } else if(Vue.prototype.isIphone && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.h5needLoginfo){
                userInfo = window.webkit.messageHandlers.h5needLoginfo.postMessage("h5needLoginfo");
            }
            /*两端的处理方式不同，安卓直接传值给h5，ios无法直接传值需要调取h5的方法传值*/
            if(Vue.prototype.isAndroid){
                initCurrentUser(userInfo)
            }
        }
        // window.sessionStorage.setItem('actCricleCart',JSON.stringify(state.cart))
    },
}
